import { actionTypes } from './../actions/actionTypes'
const admins = {
    isLogin: Boolean(JSON.parse(window.localStorage.getItem('isManagerLogin'))) || Boolean(JSON.parse(window.sessionStorage.getItem('isManagerLogin'))),
    isLoading: false,
    info: JSON.parse(window.localStorage.getItem('ManagerInfo')) || JSON.parse(window.sessionStorage.getItem('ManagerInfo'))
}

const admin = (state=admins,action) => {
    switch (action.type) {
        case actionTypes.GetAdmin: return Object.assign({},state,{
            isLogin: true,
            isLoading: false,
            info: action.data
        });
        case actionTypes.LoadingAdmin: return Object.assign({}, state, {
            isLoading: true
        })
        case actionTypes.exitAdmin: return {
            isLogin: false,
            isLoading: false,
            info: null
        };
        default:
            return state;
    }
}

export default admin;